// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({
	env:cloud.DYNAMIC_CURRENT_ENV
})

const db = cloud.database()
const _ = db.command

// 云函数入口函数
exports.main = async (event, context) => {
  const openid = cloud.getWXContext().OPENID
	const {id, currentIndex} = event
	let collectionName = ''
	// 通过index的值判断调用哪个函数
	switch (currentIndex) {
		case 0:
			collectionName = 'topics_info'
			break
		case 1:
			collectionName = 'idles_info'
			break
		case 2:
			collectionName = 'runErrands_info'
			break
		case 3:
			collectionName = 'leases_info'
			break
	}

  return await db.collection(collectionName).doc(id).get()
}